'use strict';

const lockSetKeySymbol = Symbol('app:winLockSetKey');

/**
 * 锁定窗口
 */
const locks = {
    [lockSetKeySymbol]: {},

    add(name, browserWindow) {
        if (!this.has(name)) {
            this[lockSetKeySymbol][name] = browserWindow

            const delLockKeyFunc = () => {
                delete this[lockSetKeySymbol][name]
            }

            browserWindow.webContents.on('destroyed', delLockKeyFunc)
            browserWindow.webContents.on('render-process-gone', delLockKeyFunc)
        }
    },

    has(name) {
        return (name in this[lockSetKeySymbol]) && this[lockSetKeySymbol].hasOwnProperty(name)
    },

    get(name) {
        if (this.has(name)) {
            return this[lockSetKeySymbol][name]
        }

        return undefined
    }

}

module.exports = locks